package cuilitang.hadoop.writable;

import cuilitang.hadoop.writable.bean.FlowBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WritableReducer extends Reducer<Text  ,FlowBean  ,Text, FlowBean> {




    @Override
    protected void reduce(Text keyIn,
                          Iterable<FlowBean> valuesIn,
                          Reducer<Text, FlowBean, Text, FlowBean>.Context context)
            throws IOException, InterruptedException {

        long   sumUpOut = 0;
        long   sumDownOut = 0;


        for (FlowBean fb: valuesIn) {
            sumUpOut += fb.getUpFlow();
            sumDownOut += fb.getDownFlow();

        }
        FlowBean fbOut = new FlowBean(sumUpOut,sumDownOut);



        context.write(keyIn,fbOut);




     }
}
